package com.cyd.springboot02.controller;

import com.cyd.springboot02.config.AuthorSettings;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.ApplicationContext;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

/**
 * @author keyer
 * @Description : 描述
 * Created by cyd on 2021-03-24 11:22:15
 */
@RestController
@RequestMapping(value = "/c")
public class HelloController {

    @Resource
    ApplicationContext context;

    /**
     * 直接从配置文件application.yml中拿
     */
    @Value("${book.name}")
    private String bookName;
    @Value("${book.author}")
    private String bookAuthor;

    @GetMapping(value = "/hello")
    public String hello() {
        return "hello world";
    }

    @GetMapping(value = "/getBook")
    public String getBook() {
        return "book-name:" + bookName + ",book-author:" + bookAuthor;
    }

    @GetMapping(value = "/getAuthor")
    public AuthorSettings getAuthor() {
        return context.getBean(AuthorSettings.class);
    }
}
